<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;
use think\facade\View;

class Express extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Express';

    //验证器
    protected string $validate = 'Express';

    public function index(): string
    {
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'fixed' => 'left', 'title' => '全选'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'title', 'title' => '物流公司', 'modify' => '2,input'])
            ->addColumn(['field' => 'code', 'title' => '物流编码', 'modify' => '2,input'])
            ->addColumn(['field' => 'description', 'title' => '描述', 'modify' => '2,input'])
            ->addColumn(['field' => 'sort', 'title' => '排序', 'modify' => '2,number', 'templet' => '#sort_sort', 'width' => 120])
            ->addColumn(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 200])
            ->addSortTool([['name' => 'sort', 'pk' => $this->pk, 'url' => url('update')->build()]])
            ->addSwitchTool([['name' => 'status', 'pk' => $this->pk, 'text' => '开启|关闭']])
            ->addRightButtons(['edit', 'delete'])
            ->addTopButtons(['add', 'deleteAll'])
            ->addSearch([['title|code', '物流公司/编号', 'input,Like']])
            ->fetch();
    }

    public function add($id = '', $tpl = 'express/edit', $info = ''): string
    {
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function edit($id = '', $tpl = 'express/edit', $info = ''): string
    {
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function list()
    {
        View::assign('list', []);

        return View::fetch();
    }
}